﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StructureMap;
using mitasoft.Component.Services.Interfaces;
using mitasoft.Common;
using mitasoft.Commands;

namespace mitasoft.ManagerConsole
{
    class Program
    {
        public static string FtpUsername { get; set; }
        public static string FtpPassword { get; set; }

        static void Main(string [] args)
        {
            IoC.Initialize();

            QueryForFtpCredentials();

            //FtpHelper.CopyFromFtp(FtpUsername, FtpPassword);
            MediaCommands.CopyMediaFromFtp(FtpUsername, FtpPassword);


            Console.WriteLine("Done!");
            Console.ReadLine();
        }

        static void QueryForFtpCredentials()
        {
            FtpUsername = QueryUserRecursive("FTP username:", "Please enter the FTP username !");
            FtpPassword = QueryPassword("FTP password:");
        }

        static string QueryPassword(string label)
        {
            var initialBackground = Console.BackgroundColor;
            var initialColor = Console.ForegroundColor;

            Console.Write(label);
            
            // protect password chars
            Console.ForegroundColor = ConsoleColor.Black;
            string value = Console.ReadLine();
            Console.ForegroundColor = initialColor;

            return value;
        }
        static string QueryUserRecursive(string label, string errorMessage)
        {
            string value = QueryUser(label);

            while (string.IsNullOrEmpty(value))
            {
                if (string.IsNullOrEmpty(value))
                {
                    Console.WriteLine(errorMessage);
                }

                value = QueryUser(label);
            }

            return value;
        }

        static string QueryUser(string label)
        {
            Console.Write(label);
            return Console.ReadLine();
        }

        static void Do()
        {
            var blogService = ObjectFactory.GetInstance<IBlogService>();
            var result = blogService.GetCategories();

            //new FtpHelper().ListContent();
        }
    }
}
